﻿<!DOCTYPE>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath(); 
	//获得本项目的地址(例如: http://localhost:8080/MyApp/)赋值给basePath变量 
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	pageContext.setAttribute("basePath",basePath); 
	pageContext.setAttribute("path",path); 
%>    
<html>
<head>
<link rel="stylesheet" type="text/css" href="${basePath}css/style.css"/>
<script type="text/javascript" src="${basePath}js/jquery-3.2.1.js"></script>
<title>登录</title>
<meta content="description" name="description">
<meta content="keywords" name="keywords">
</head>

<body id="login_bg">
	<div class="login_wrapper">
		
        
		 <div class="login_box">
        	<form id="loginForm" action="${basePath}user/login" method="post">
				<input type="text" id="email" name="email" value="" tabindex="1" placeholder="请输入登录邮箱地址" />
			  	<input type="password" id="password" name="password" tabindex="2" placeholder="请输入密码" />
			    
				<a style="color:#fff;" href="javascript:check();" class="submitLogin" title="登 &nbsp; &nbsp; 录"/>登 &nbsp; &nbsp; 录</a>
				<!-- <a type="submit" id="submitLogin" value="登 &nbsp; &nbsp; 录" /> -->
			</form>
			<div class="login_right">
				<div>还没有帐号？</div>
				<a  href="${basePath}common/register"  class="registor_now">立即注册</a>
			   
			</div>
        </div>
        <div class="login_box_btm"></div>
    </div>

<script type="text/javascript">

function check(){
		var email =$('#email').val();
		var password =$('#password').val();
		if(email == null || email == undefined){alert("请输入邮箱");return ;}
		if(password == null || email == undefined){alert("请输入密码");return ;}
		$.ajax({
			type:'POST',
        	data: {email:email,password:password},
        	url:'${basePath}user/login',
        	dataType:'json',
        	success:function(result){
        		console.log("success");
        		var model = result.model;
            	if(model.code==0){
            		//进入主页
            		console.log(model.msg);
            		window.location.href="${basePath}" + model.href;
            	}else{
            		alert(model.msg);
            		console.log(model.msg);
            	}
        	}
		});
}

$(function(){
	
	
	
	//验证表单
	 	/* $("#loginForm").validate({
	 		
	        rules: {
	    	   	email: {
	    	    	required: true,
	    	    	email: true
	    	   	},
	    	   	password: {
	    	    	required: true
	    	   	}
	    	},
	    	messages: {
	    	   	email: {
	    	    	required: "请输入登录邮箱地址",
	    	    	email: "请输入有效的邮箱地址，如：vivi@lagou.com"
	    	   	},
	    	   	password: {
	    	    	required: "请输入密码"
	    	   	}
	    	},
	    	submitHandler:function(form){
	    		if($('#remember').prop("checked")){
	      			$('#remember').val(1);
	      		}else{
	      			$('#remember').val(null);
	      		}
	    		var email = $('#email').val();
	    		var password = $('#password').val();
	    		var remember = $('#remember').val();
	    		
	    		var callback = $('#callback').val();
	    		var authType = $('#authType').val();
	    		var signature = $('#signature').val();
	    		var timestamp = $('#timestamp').val();
	    		
	    		$(form).find(":submit").attr("disabled", true);
	            $.ajax({
	            	type:'POST',
	            	data:{email:email,password:password,autoLogin:remember, callback:callback, authType:authType, signature:signature, timestamp:timestamp},
	            	url:ctx+'/user/login.json'
	            }).done(function(result) {
					if(result.success){
					 	if(result.content.loginToUrl){
							window.location.href=result.content.loginToUrl;
	            		}else{
	            			window.location.href=ctx+'/';
	            		} 
					}else{
						$('#beError').text(result.msg).show();
					}
					$(form).find(":submit").attr("disabled", false);
	            }); 
	        }  
		}); */
});
</script>
</body>
</html>